import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { readResourse } from "./utils.js";

const server = new McpServer({
  name: "resources-server",
  version: "0.1.0",
});

// 注册文本资源（非二进制）
server.registerResource(
  "香蕉手机", // 资源的名称
  "bananaphone://info", // 资源URI
  {
    title: "香蕉手机信息",
    description: "香蕉手机的产品以及特性的介绍文字",
    mimeType: "text/plain",
  },
  async (uri) => {
    console.error("uri>>>", uri);
    const content = await readResourse("src/assets", "bananaphone.txt", false);
    return {
      contents: [
        {
          uri: uri.href,
          name: "香蕉手机信息",
          text: content,
        },
      ],
    };
  }
);

// 注册图像资源（二进制）
server.registerResource(
  "书籍图片", // 资源的名称
  "pics://books", // 资源URI
  {
    title: "书籍图片",
    description: "一张有很多书籍的图片",
    mimeType: "image/jpeg",
  },
  async (uri) => {
    console.error("uri>>>", uri);
    const content = await readResourse("src/assets", "books.jpeg", true);
    return {
      contents: [
        {
          uri: uri.href,
          name: "书籍图片",
          blob: content,
        },
      ],
    };
  }
);

const transport = new StdioServerTransport();
await server.connect(transport);
